import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { SPanicBuyItemMsg } from "../../../../Message/Game/SPanicBuyItemMsg";
import { SPanicBuyShopForMsg } from "../../../../Message/Game/SPanicBuyShopForMsg";
import { ItemData } from "../../resource/info/ItemData";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { BaseItem } from "../common/BaseItem";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ItemConfig } from "../../resource/ItemConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { MallBuyBatchPanel } from "./MallBuyBatchPanel";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PreviewType } from "./PreviewType";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { PreviewPet } from "../../../../PreviewType/PreviewPet";
import { PreviewMount } from "../../../../PreviewType/PreviewMount";
type int = number;
//class PreferenRender
    
    export  class PreferenRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.createChildren();
            return;
        }

        /* internal  */updatePanicBuyBitmap(): void
        {
            this._panicBuyLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.PreperenLabel);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this.panicBuyItemMsg = arg1["panicBuyItemMsg"] as SPanicBuyItemMsg;
            this.panicBuyShop = arg1["panicBuyShop"] as SPanicBuyShopForMsg;
            this.itemData = new ItemData(this.panicBuyItemMsg.itemCode);
            this._propItem.itemData = this.itemData;
            this._propItem.drawNow();
            this._propItem.amount = -1;
            this._propItem.setSize(60, 60);
            this._nameTxt.htmlText = this.getNameText(this.panicBuyItemMsg.itemCode);
            this._oPriceNumTxt.htmlText = this.panicBuyItemMsg.price.toString();
            this._pPriceNumTxt.htmlText = this.panicBuyItemMsg.discount.toString();
            var loc1=Cache.instance.shop.panicBuyDict[this._panicBuyItemMsg.itemCode];
            this._leftAmountSelf = this._panicBuyItemMsg.buyLimit - loc1;
            this._buyLimitTxt.text = Language.getStringByParam(90223, this._leftAmountSelf.toString());
            if (this.panicBuyItemMsg.leftAmount <= 999) 
            {
                this._remainderTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(53010, this.panicBuyItemMsg.leftAmount), "#00ff00");
            }
            else 
            {
                this._remainderTxt.htmlText = HTMLUtil.addColor(Language.getString(53011), "#B1EEFF");
            }
            var loc2=this._oPriceNumTxt.x + this._oPriceNumTxt.width;
            var loc3=this._oPriceNumTxt.y + this._oPriceNumTxt.height;
            this._redLine.graphics.clear();
            this._redLine.graphics.lineStyle(2, 16711680, 0.75);
            this._redLine.graphics.moveTo(this._oPriceNumTxt.x, this._oPriceNumTxt.y);
            this._redLine.graphics.lineTo(loc2, loc3);
            if (this.itemData.category == ECategory._ECategoryMount || this.itemData.category == ECategory._ECategoryProp && this.itemData.type == EProp._EPropPetEgg) 
            {
                if (this._previewBtn == null) 
                {
                    this._previewBtn = ObjCreate.createGLoadedButton(ResFileConst.Preview, 45, 45, 22, 22, this);
                    this._previewBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onPreviewBtnClickHandler);
                }
                this._previewBtn.drawNow();
                this.addChild(this._previewBtn);
            }
            else if (this._previewBtn && this.contains(this._previewBtn)) 
            {
                this.removeChild(this._previewBtn);
            }
            return;
        }

        protected createChildren(): void
        {
            this._propBg = ObjCreate.createBitmap(ImagesConst.PropBg, 0, 0, this);
            this._propItem = new BaseItem();
            this._propItem.label = "";
            this._propItem.move(5, 5);
            this._propItem.isDragAble = false;
            this.addChild(this._propItem);
            this._panicBuyLabel = new Object /* flash.display.Bitmap */();
            this._panicBuyLabel.x = 0;
            this._panicBuyLabel.y = 0;
            this._panicBuyLabel.visible = true;
            this.addChild(this._panicBuyLabel);
            LoaderHelp.addResCallBack(ResFileConst.shopMall, this.updatePanicBuyBitmap);
            this._nameTxt = ObjCreate.createTextField("", 70, 0, 140, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createTextField(Language.getString(53013), 70, 25, 140, 20, this);
            this._oPriceNumTxt = ObjCreate.createTextField("", 105, 25, 25, 20, this);
            this._oPriceNumTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._redLine = new Object /* flash.display.Shape */();
            this.addChild(this._redLine);
            ObjCreate.createTextField(Language.getString(53014), 70, 45, 140, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._pPriceNumTxt = ObjCreate.createTextField("", 105, 45, 25, 20, this, GlobalStyle.textFormat6);
            this._pPriceNumTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._oIngot = GlobalClass.getBitmap(ImagesConst.Yuanbao_small);
            this._oIngot.x = 135;
            this._oIngot.y = 25;
            this.addChild(this._oIngot);
            this._pIngot = GlobalClass.getBitmap(ImagesConst.Yuanbao_small);
            this._pIngot.x = 135;
            this._pIngot.y = 45;
            this.addChild(this._pIngot);
            this._remainderTxt = ObjCreate.createTextField("", 155, 0, 70, 25, this);
            this._buyNumTxt = ObjCreate.createTextField(Language.getString(90224), 155, 20, 140, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._buyLimitTxt = ObjCreate.createTextField("", 195, 20, 140, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._buyBtn = ObjCreate.createGButton(Language.getString(90225), 170, 40, 48, 25, this, "ButtonRedMini");
            this._buyBtn.drawNow();
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            (this._buyBtn.getChildAt(1) as Object /* flash.text.TextField */).filters = [FilterConst.nameGlowFilter];
            this.addChild(this._buyBtn);
            this._septalLine = GlobalClass.getBitmap("SeptalLine");
            this._septalLine.x = 5;
            this._septalLine.y = 70;
            this.addChild(this._septalLine);
            return;
        }

        public getNameText(arg1: int): string
        {
            var loc3=null;
            var loc5=null;
            var loc1="";
            var loc2="";
            var loc4;
            if (loc4 = ItemConfig.instance.getInfoByCode(arg1)) 
            {
                loc3 = loc4.item;
            }
            if (loc3) 
            {
                loc1 = loc3.name;
                if (loc5 = ColorConfig.instance.getItem("item", loc3.color.toString())) 
                {
                    loc2 = loc5.color;
                }
            }
            return HTMLUtil.addColor("<font size=\'14\'>" + loc1 + "</font>", loc2);
        }

        protected onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._leftAmountSelf > 1 && this._panicBuyItemMsg.leftAmount > 0) 
            {
                if (this._buyBatchPanel == null) 
                {
                    this._buyBatchPanel = new MallBuyBatchPanel();
                }
                this._buyBatchPanel.showCenter = false;
                this._buyBatchPanel.show();
                this._buyBatchPanel.update(this.panicBuyItemMsg);
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PanicBuyItem, {"itemCode": this.panicBuyItemMsg.itemCode, "amount": 1}));
            }
            return;
        }

        public get panicBuyItemMsg(): SPanicBuyItemMsg
        {
            return this._panicBuyItemMsg;
        }

        public set panicBuyItemMsg(arg1: SPanicBuyItemMsg)
        {
            this._panicBuyItemMsg = arg1;
            return;
        }

        protected onPreviewBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            if (this.itemData.category != ECategory._ECategoryMount) 
            {
                loc1 = this.itemData.itemInfo.item.effect;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMountPreview, {"type": PreviewPet, "code": loc1}));
            }
            else 
            {
                loc1 = this.itemData.itemInfo.item.code;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMountPreview, {"type": PreviewMount, "code": loc1}));
            }
            return;
        }

        protected /* var */_propBg: Object /* flash.display.Bitmap */;

        protected /* var */_remainningTimeBg: Object /* flash.display.Bitmap */;

        protected /* var */_propItem: BaseItem;

        protected /* var */_nameTxt: Object /* flash.text.TextField */;

        protected /* var */_oPriceLabel: GLabel;

        protected /* var */_pPriceLabel: GLabel;

        protected /* var */_oPriceNumTxt: Object /* flash.text.TextField */;

        protected /* var */_pPriceNumTxt: Object /* flash.text.TextField */;

        protected /* var */_oIngot: Object /* flash.display.Bitmap */;

        protected /* var */_pIngot: Object /* flash.display.Bitmap */;

        protected /* var */_buyLimitTxt: Object /* flash.text.TextField */;

        protected /* var */_buyBtn: GButton;

        protected /* var */_windowCenterB: Object /* flash.display.Bitmap */;

        protected /* var */_panicBuyLabel: Object /* flash.display.Bitmap */;

        protected /* var */_remainderTxt: Object /* flash.text.TextField */;

        protected /* var */_redLine: Object /* flash.display.Shape */;

        protected /* var */_previewBtn: GLoadedButton;

        protected /* var */_buyNumTxt: Object /* flash.text.TextField */;

        protected /* var */_panicBuyItemMsg: SPanicBuyItemMsg;

        /* internal */ /* var */_buyBatchPanel: MallBuyBatchPanel;

        protected /* var */panicBuyShop: SPanicBuyShopForMsg;

        protected /* var */itemData: ItemData;

        protected /* var */_leftSeconds: number;

        protected /* var */_leftAmountSelf: int;

        protected /* var */_septalLine: Object /* flash.display.Bitmap */;
    }
